package grape.composite.rest.logresterror.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.composite.rest.logresterror.form.LogRestErrorCreateForm;
import grape.composite.rest.logresterror.form.LogRestErrorListPageForm;
import grape.composite.rest.logresterror.mapper.LogRestErrorWebMapper;
import grape.composite.rest.logresterror.vo.LogRestErrorVo;
import grape.composite.service.logresterror.api.ILogRestErrorService;
import grape.composite.service.logresterror.po.LogRestError;
import grape.common.AbstractLoginUser;
import grape.common.rest.mvc.BaseController;
import grape.common.service.loginuser.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
/**
 * <p>
 * 接口请求异常日志表 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-03-09
 */
@RestController
@RequestMapping("/composite/logresterror")
@Api(tags = "接口请求异常日志相关接口")
public class LogRestErrorController extends BaseController<LogRestErrorVo, LogRestError> {

    @Autowired
    private LogRestErrorWebMapper currentWebMapper;
    @Autowired
    private ILogRestErrorService currentService;



     @ApiOperation("添加接口请求异常日志表")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public LogRestErrorVo create(@RequestBody @Valid LogRestErrorCreateForm cf) {
         LogRestError po = currentWebMapper.formToPo(cf);
         Object loginUser = AbstractLoginUser.getLoginUser();
         if (loginUser != null) {
             po.setUserId(((LoginUser) loginUser).getId());
         }
         return super.create(po);
     }

     @ApiOperation("根据ID查询接口请求异常日志表")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public LogRestErrorVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除接口请求异常日志表")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }


    @ApiOperation("分页查询接口请求异常日志")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<LogRestErrorVo> listPage(LogRestErrorListPageForm listPageForm) {
         LogRestError po = currentWebMapper.formToPo(listPageForm);
         return super.listPage(po,listPageForm);
     }

}
